package com.miaoji.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.miaoji.domain.po.UserInfo;
import com.miaoji.mapper.UserInfoMapper;
import com.miaoji.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public UserInfo UserLogin(UserInfo userInfo) {
        UserInfo result = userInfoMapper.login(userInfo.getLoginName(), userInfo.getPassword());
        //System.out.println(result);
        if (result != null) {
            System.out.println("Found record with name " + result);

        } else {
            System.out.println("{"+"  \"status\": \"500\"," +"\t\"info\":\"未找到信息\"," +"\t\"success\":1\n" +"}");
        }
        return result;
    }

    @Override
    public String UserSelect() {//返回用户信息
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<UserInfo>().select("id","user_name","mobile","gender","state","file_name").ne("state", 2);
        //查询
        List<UserInfo> userInfos = userInfoMapper.selectList(queryWrapper);
        return JSON.toJSONString(userInfos);
       // userInfoMapper.selectList();
    }

    @Override
    public void UserUpdateState(int id,int state) {
        UpdateWrapper<UserInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("state", state).eq("id", id);
        userInfoMapper.update(null, updateWrapper);
    }
}
